import Action from './Action'

export default class imgCache extends Action {
    columns: any
    tableIndexArr: Array<any>
    constructor() {
        super()
        this.tableName = 'image_cache'

        this.columns = {
            id: 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL',
            url: 'VARCHAR(128)', // 网络地址
            local: 'VARCHAR(128)' // 本地缓存
        }

        this.tableIndexArr = [
            { name: 'idx_image_cache_url', key: 'url' },
            { name: 'idx_image_cache_local', key: 'local' },
        ]
    }
    /** 查询图片有没有缓存本地 */
    getCache(url: string) {
        return new Promise((resolve, reject) => {
            super
                .getList({
                    where: `where url = "${url.toString()}"`
                })
                .then((res: any) => {
                    resolve(res)
                })
                .catch(e => {
                    resolve(null)
                })
        })
    }
    /**
     * 置零 未选择的规格
     * @param {arr}  当前有数据的sku数组
     */
    // clearSkuCountNotSelect(userId: string | number, releaseId: string | number, arr: Array<any>) {
    //     let condition = ''
    //     if (arr.length > 0) {
    //         condition = ` and sku_id not IN (${arr.toString()})`
    //     }
    //     let a = this.executeOptions({
    //         model: this.QUERY_CUSTOM,
    //         sql: `UPDATE sku_count SET count = 0 where user_id = ${userId} and release_id = ${releaseId} ${condition}`
    //     })
    //     return this.execute(a)
    // }
}
